package net.cyue.web.easyquery.core.http.data;

import net.cyue.web.easyquery.core.db.data.QueryPageResult;
import net.cyue.web.easyquery.core.http.HTTPStatus;

import java.util.Date;

/**
 * 默认的 Page版 WebResult
 */
public class DefaultWebPageResult extends DefaultWebResult {

    private QueryPageResult page;

    private DefaultWebPageResult() {}


    /**
     * 创建一个成功结果
     * @return DefaultWebPageResult
     */
    public static DefaultWebPageResult success(QueryPageResult page) {
        DefaultWebPageResult result = new DefaultWebPageResult();
        result.time = new Date();
        result.code = HTTPStatus.OK;
        result.status = Status.SUCCESS;
        result.page = page;
        return result;
    }

    /**
     * 创建一个成功结果
     * @param message 提示信息
     * @return DefaultWebPageResult
     */
    public static DefaultWebPageResult success(String message, QueryPageResult page) {
        DefaultWebPageResult result = DefaultWebPageResult.success(page);
        result.message = message;
        return result;
    }

    /**
     * 创建一个成功结果
     * @param message 提示信息
     * @param data 数据
     * @return DefaultWebPageResult
     */
    public static DefaultWebPageResult success(String message, Object data, QueryPageResult page) {
        DefaultWebPageResult result = DefaultWebPageResult.success(message, page);
        result.data = data;
        return result;
    }

    /**
     * 创建一个失败结果
     * @return DefaultWebPageResult
     */
    public static DefaultWebPageResult failure(QueryPageResult page) {
        DefaultWebPageResult result = new DefaultWebPageResult();
        result.time = new Date();
        result.code = HTTPStatus.BAD_REQUEST;
        result.status = Status.FAILURE;
        result.page = page;
        return result;
    }

    /**
     * 创建一个失败结果
     * @param message 提示信息
     * @return DefaultWebPageResult
     */
    public static DefaultWebPageResult failure(String message, QueryPageResult page) {
        DefaultWebPageResult result = DefaultWebPageResult.failure(page);
        result.message = message;
        return result;
    }

    /**
     * 创建一个错误结果
     * @return DefaultWebPageResult
     */
    public static DefaultWebPageResult error(QueryPageResult page) {
        DefaultWebPageResult result = new DefaultWebPageResult();
        result.time = new Date();
        result.code = HTTPStatus.INTERNAL_SERVER_ERROR;
        result.status = Status.ERROR;
        result.page = page;
        return result;
    }

    /**
     * 创建一个错误结果
     * @param message 提示信息
     * @return DefaultWebPageResult
     */
    public static DefaultWebPageResult error(String message, QueryPageResult page) {
        DefaultWebPageResult result = DefaultWebPageResult.error(page);
        result.message = message;
        return result;
    }
}
